<?php
namespace app\admin\controller;

use app\common\model\ApplyReg;
use app\common\model\Shops;
use think\Db;
use think\Request;

class Register extends Base
{

    /**
     * @route('admin/register')
     * 商铺注册
     */
    public function register()
    {
        $username = $this->regpost('username','string');
        $shopname = $this->regpost('shopname','string');
        $phone = $this->regpost('phone','string');
        $province = $this->regpost('province','string');
        $city = $this->regpost('city','string');
        $area = $this->regpost('area','string');
        $province_id = $this->regpost('province_id','int');
        $city_id = $this->regpost('city_id','int');
        $area_id = $this->regpost('area_id','int');
        $address = $this->regpost('address','string');
        $shop_manager = $this->regpost('shop_manger','string');
        $imagesurl = $this->regpost('imagesurl','string');
        $idcardfront = $this->regpost('idcardimg1','string');
        $idcardbefore = $this->regpost('idcardimg2','string');
        $licenseimg = $this->regpost('licenseimg','string');
        $pass = $this->regpost('user_pass','string');
        $lon = $this->regpost('lon','string');
        $lat = $this->regpost('lat','string');
        $type = $this->regpost('type','int');
        $remark = $this->regpost('remark','string');
        $salecode = $this->regpost('salecode','int');
        $shop = Shops::where('shopphone',$phone)->find();
//        var_dump($shop);die;
        if($shop){
            $this->result('','-1','该手机号注册商铺已存在');
        }
        $data = [
            "username" => $username,
            "shopname" => $shopname,
            "telphone" => $phone,
            "province" => $province,
            "province_id" => $province_id,
            "city" => $city,
            "city_id" => $city_id,
            "area" => $area,
            "area_id" => $area_id,
            "address" => $address,
            "shop_manager" => $shop_manager,
            "imagesurl" => $imagesurl,
            "idcardimg1" => $idcardfront,
            "idcardimg2" => $idcardbefore,
            "licenseimg" => $licenseimg,
            "user_pass" => $pass,
            "lon" => $lon,
            "lat" => $lat,
            "apply_type" => $type,
            "remark" => $remark,
            "salecode" => $salecode,
        ];
        $applymodel = new ApplyReg();
        $result = $applymodel->edit($data);
//        var_dump($result);
        if(!$result){
            $this->result('','-1',$applymodel->getError());
        }
        $this->result('','1','申请成功');
    }

}
